#include "bullet.h"
#include "config.h"

Bullet::Bullet()
{
    // 加载子弹资源
    m_bullet.load(BULLET_PATH);
    // 子弹坐标
    m_x = GAME_WIDTH / 2 - m_bullet.width() / 2;
    m_y = GAME_HEIGHT / 2 - m_bullet.height() / 2;
    // 子弹状态
    m_free= true;
    // 子弹速度
    m_speed = BULLET_SPEED;
    // 子弹边框
    m_rect.setWidth(m_bullet.width());
    m_rect.setHeight(m_bullet.height());
    m_rect.moveTo(m_x, m_y);
}

void Bullet::updatePosition()
{
    if (m_free)
    {
        return;
    }
    // 子弹向上移动
    m_y -= m_speed;
    m_rect.moveTo(m_x, m_y);
    if (m_y <= -m_rect.height())
    {
        m_free = true;
    }
}
